package com.damuzee.cms.model.action;

import javax.annotation.Resource;

import org.mybatis.sql.condition.Criteria;
import org.mybatis.sql.page.Page;
import org.mybatis.sql.page.Pagination;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.damuzee.cms.model.domain.FieldType;
import com.damuzee.cms.model.persistence.FieldTypeMapper;
import com.damuzee.cms.model.service.IFieldTypeService;
import com.damuzee.core.action.BaseAction;
import com.damuzee.weixin.config.domain.AccoutBind;

@Controller
public class ModuleAction extends BaseAction {
	
	@RequestMapping(value="/module/add.do")
	public String add(){
		return  "/module/add" ;
	}
	
	@RequestMapping(value="/module/list.do")
	public String list(){
		return  "/module/list" ;
	}
	
	@RequestMapping(value="/module/list.do",method = RequestMethod.POST)
	@ResponseBody
	public Pagination<FieldType> list(Integer pageNum, Integer totalCount ,Integer pageSize ,
			String orderby, String order , ModelMap map){
		Page<FieldType> page = new Page<FieldType>();
		page.setCurrentPage(pageNum);
		if(totalCount != null){
			page.setTotal(totalCount);
		}
		page.setSize(pageSize);
		Criteria cri = new Criteria(FieldType.class);
		
		if(orderby!= null && order != null ){
			cri.order(orderby, order);
		}
		
		page = fieldTypeMapper.selectPageByCriteria(page, cri);
		return  page.getPage();
	}
	
	@RequestMapping(value="/module/save.do")
	@ResponseBody
	public String save(FieldType fieldType){
		
		fileTypeService.saveFieldType(fieldType);
		return  "/module/add" ;
	}
	
	@Resource
	IFieldTypeService fileTypeService ;
	
	@Resource
	FieldTypeMapper fieldTypeMapper ;
}
